<template>
  <div style="background-color: white; margin-top: -5px; min-height: 100vh">
    <van-form @submit="submitForm" readonly>
      <searchable-picker
        v-model="form.required"
        :columns="dict.type.is_required"
        valueKey="value"
        labelKey="label"
        label="有无验收表"
        placeholder="请选择有无验收表"
        readonly
        :rules="[{ required: true, message: '请选择有无验收表' }]"
      />

      <searchable-picker
        v-model="form.orderId"
        :columns="orderList"
        valueKey="orderId"
        labelKey="orderName"
        label="项目名称"
        placeholder="请选择项目"
        readonly
      />

      <searchable-picker
        v-model="form.customerId"
        :columns="customerList"
        valueKey="customerId"
        labelKey="customerName"
        label="客户名称"
        placeholder="请选择客户名称"
        readonly
      />

      <van-field
        v-model="form.projectUnit"
        v-if="form.required === '1'"
        label="项目单位"
        placeholder="请输入项目单位"
        :rules="[{ required: true, message: '请输入项目单位' }]"
      />

      <van-field
        v-if="form.required === '1'"
        v-model="form.projectContacts"
        label="联系人"
        placeholder="请输入联系人"
        :rules="[{ required: true, message: '请输入联系人' }]"
      />
      <van-field
        v-if="form.required === '1'"
        v-model="form.phone"
        label="联系电话"
        placeholder="请输入联系电话"
        :rules="[{ required: true, message: '请输入联系电话' }]"
      />

      <van-field
        v-model="form.receptionTime"
        v-if="form.required === '1'"
        label="验收日期"
        placeholder="请选择验收日期"
        :rules="[{ required: true, message: '验收日期不能为空' }]"
      />
      <van-field
        v-model="form.startTime"
        v-if="form.required === '1'"
        label="开始时间"
        placeholder="请选择开始时间"
        :rules="[{ required: true, message: '开始时间不能为空' }]"
      />

      <van-field
        v-model="form.endTime"
        v-if="form.required === '1'"
        label="结束时间"
        placeholder="请选择结束时间"
        :rules="[{ required: true, message: '结束时间不能为空' }]"
      />
      <van-field
        name="uploader"
        label="项目验收单"
        v-if="form.required === '1'"
      >
        <template #input>
          <file-upload v-model="form.url" />
        </template>
      </van-field>

      <div class="mobile-footer">
        <van-button
          type="info"
          native-type="submit"
          style="width: 90%; border-radius: 10px"
          >办理</van-button
        >
      </div>
    </van-form>
     <auditComponent ref="auditComponent" @handle="handleBtn"></auditComponent>
  </div>
</template>

<script>
import { getSheet, audit } from "@/api/crm/sheet";

import { getCrmOrderAllNoPage } from "@/api/crm/order";
import { getCrmCustomerAllNoPage } from "@/api/crm/customer";
import auditComponent from "../components/auditComponent.vue";
export default {
  name: "Approve",
  dicts: ["is_required"],
  components: { auditComponent },
  data() {
    return {
      deptOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 指定跳转节点
      nodeCode: "",
      customerList: [],
      orderList: [],
      value: '',
      taskId: ''
    };
  },
  created() {
    this.value = this.$route.query.value;
    this.taskId = this.$route.query.taskId;
    this.getCrmCustomerAllNoPage();
    this.getCrmOrderAllNoPage();
    this.getSheet();
  },
  methods: {

    getCrmOrderAllNoPage() {
      getCrmOrderAllNoPage({}).then((res) => {
        this.orderList = res.data;
      });
    },
    getUserListByStatus() {
      getUserListByStatus({ status: "0" }).then((res) => {
        this.userList = res.data;
      });
    },
    getCrmCustomerAllNoPage() {
      getCrmCustomerAllNoPage({}).then((res) => {
        this.customerList = res.data;
      });
    },
    async getSheet() {
      await getSheet(this.value).then((response) => {
        if (!response.data) {
          this.$modal.alertWarning("代办任务不存在");
        }
        this.form = response.data;
        this.title = this.form.createBy + " 项目验收";
        this.open = true;
      });
    },
    submitForm(){
      this.$refs.auditComponent.open();
    },
    /** 审核通过按钮 */
    handleBtn(obj) {
        this.form.taskId = this.taskId;
        this.form.message = obj.message
        this.form.signature = obj.signature
        this.form.skipType = obj.skipType
        audit(this.form).then((response) => {
          this.$toast.success("办理成功");
          this.$router.replace("/flow/todo")
        }); 
    },
  },
};
</script>
<style scoped>
</style>
